package fatboy.hypeerweb;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.junit.Test;



public class TestNodeAdd {
	private static final int ADD_ORDER_TEST_LENGTH = 25;

	/**
	 * test that nodes are added in the correct order
	 */
	@Test
	public void testAddOrder(){
		Connection test = new Connection();
		for(int i = 0; i < ADD_ORDER_TEST_LENGTH; i++){
			Node recentNode = test.addNode(i);
			//gets NodeAddresses int value
			int spot = recentNode.getAddress().getAddress();
			assertEquals(i, spot);
		}
	}
	/**
	 * test Node status after small adds
	 */
	@Test
	public void testAddStatus(){
		Connection test = new Connection();
		Node first = test.addNode("first");
		Node second = test.addNode("second");
		Node third = test.addNode("third");
		assertEquals(third,second.getFoldPointer());
		assertEquals(second,first.getFoldPointer());
		assertTrue(third.getNeighbors().contains(first));
		assertEquals(1, third.getNeighbors().size());
		assertTrue(first.getNeighbors().contains(second));
		assertTrue(first.getNeighbors().contains(third));
		assertEquals(2, first.getNeighbors().size());
		assertTrue(second.getNeighbors().contains(first));
		assertEquals(1, second.getNeighbors().size());
		assertTrue(second.getPointers().contains(new EdgePointer(third)));
		assertTrue(third.getPointers().contains(new SurrogatePointer(second)));
		assertEquals(1, third.getPointers().size());
		assertEquals(1, second.getPointers().size());
	}
	/**
	 * check for proper handling of invalid data
	 */
	@Test (expected = IllegalArgumentException.class)
	public void testInvalidInput(){
		Connection test = new Connection();
		test.addNode(null);
		fail();
	}
}
